﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using SeasideResearch.LibCurlNet;
using System.Threading;

namespace SemestralniPraceY35VAN
{
    class Foursquare
    {
        public const string USER_AGENT = "foursquare-framework:0.1";

        public const string URL_USER_DETAIL = @"http://api.foursquare.com/v1/user";
        public const string URL_CHECK_IN = @"http://api.foursquare.com/v1/checkin";
        public const string URL_CHECKINS = @"http://api.foursquare.com/v1/checkins";
        public const string URL_HISTORY = @"http://api.foursquare.com/v1/history";
        public const string URL_TEST = @"http://api.foursquare.com/v1/test";
        public const string URL_FRIENDS = @"http://api.foursquare.com/v1/friends";
        public const string URL_SEARCH_NEARBY = @"http://api.foursquare.com/v1/venues";
        public const string URL_VENUE_DETAILS = @"http://api.foursquare.com/v1/venue";
        public const string URL_ADD_VENUE = @"http://api.foursquare.com/v1/addvenue";
        public const string URL_PROPOSE_EDIT = @"http://api.foursquare.com/v1/venue/proposeedit";
        public const string URL_TIPS_NEARBY = @"http://api.foursquare.com/v1/tips";
        public const string URL_ADD_TIP = @"http://api.foursquare.com/v1/addtip";
        public const string URL_MARK_TODO = @"http://api.foursquare.com/v1/tip/marktodo";
        public const string URL_MARK_DONE = @"http://api.foursquare.com/v1/tip/markdone";
        public const string URL_UNMARK = @"http://api.foursquare.com/v1/tip/unmark";
        public const string URL_PENDING_REQUESTS = @"http://api.foursquare.com/v1/friend/requests";
        public const string URL_APPROVE_REQUEST = @"http://api.foursquare.com/v1/friend/approve";
        public const string URL_DENY_REQUEST = @"http://api.foursquare.com/v1/friend/deny";
        public const string URL_SEND_REQUEST = @"http://api.foursquare.com/v1/friend/sendrequest";
        public const string URL_BY_NAME = @"http://api.foursquare.com/v1/findfriends/byname";
        public const string URL_BY_PHONE = @"http://api.foursquare.com/v1/findfriends/byphone";
        public const string URL_BY_TWITTER = @"http://api.foursquare.com/v1/findfriends/bytwitter";
        public const string URL_SET_PINGS = @"http://api.foursquare.com/v1/settings/setpings";

        private string username;
        private string password;
        private bool debug;

        private User user;

        /// <summary>
        /// 
        /// </summary>
        public User User {
            get {
                if (this.user == null)
                {
                    this.user = this.getUserDetail(true, true);
                }

                return this.user;
            }
        }

        ////////////////////////////////////////////////////////////////////////
        /// CONSTRUCTOR ////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public Foursquare(string username, string password)
        {
            this.username = username;
            this.password = password;
            this.debug = false;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public Foursquare(string username, string password, bool debug)
        {
            this.username = username;
            this.password = password;
            this.debug = debug;
        }

        ////////////////////////////////////////////////////////////////////////
        /// CHECK IN METHODS ///////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns a list of recent checkins from friends.
        /// </summary>
        /// <returns>list of recent checkins from friends</returns>
        public List<Checkin> getCheckins()
        {
            return getCheckins(null, null);
        }

        /// <summary>
        /// Returns a list of recent checkins from friends.
        /// </summary>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns>list of recent checkins from friends</returns>
        public List<Checkin> getCheckins(string geolat, string geolong)
        {
            string parameters = null;

            if (!String.IsNullOrEmpty(geolat) && !String.IsNullOrEmpty(geolong))
            {
                parameters = "geolat=" + geolat + "&geolong=" + geolong;
            }

            XmlDocument xml;

            if (this.debug)
            {
                xml = Downloader.stringToXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><checkins><checkin><id>42577387</id><created>Wed, 12 May 10 11:30:54 +0000</created><timezone>Europe/Prague</timezone><ismayor>true</ismayor><venue><id>1646088</id><name>Ostrava, Svinov mosty - horní zastávka</name><primarycategory><id>96362</id><fullpathname>Travel:Bus Station:Bus</fullpathname><nodename>Bus</nodename><iconurl>http://foursquare.com/img/categories/travel/busstation.png</iconurl></primarycategory><address>Opavská</address><city>Ostrava - Svinov</city><state>Česká republika</state><zip>721 00</zip><geolat>49.824307438043455</geolat><geolong>18.21032166481018</geolong></venue><user><id>322908</id><firstname>Jakub</firstname><lastname>Kotzot</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/S1PQ45MVD1SHDRAC.jpg</photo><gender>male</gender></user><display>Jakub K. @ Ostrava, Svinov mosty - horní zastávka</display><ping>false</ping></checkin><checkin><id>42567455</id><created>Wed, 12 May 10 11:03:18 +0000</created><timezone>Europe/Prague</timezone><venue><id>1871057</id><name>U žíznivého Jelena</name><primarycategory><id>79170</id><fullpathname>Nightlife:Pub</fullpathname><nodename>Pub</nodename><iconurl>http://foursquare.com/img/categories/nightlife/default.png</iconurl></primarycategory><address>Vltavská 533/22</address><crossstreet>Nádražní</crossstreet><city>Prague</city><state>Czech Republic</state><zip>15000</zip><geolat>50.069639163439554</geolat><geolong>14.406487941741943</geolong></venue><user><id>738780</id><firstname>Lukas</firstname><lastname>Honzak</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/0IQIGGFW2FIC3UUG.jpg</photo><gender>male</gender></user><display>Lukas H. @ U žíznivého Jelena</display><ping>true</ping></checkin><checkin><id>42560171</id><created>Wed, 12 May 10 10:40:44 +0000</created><timezone>Europe/Prague</timezone><ismayor>true</ismayor><venue><id>476767</id><name>Galerie Fenix</name><primarycategory><id>79273</id><fullpathname>Travel:Hotel</fullpathname><nodename>Hotel</nodename><iconurl>http://foursquare.com/img/categories/travel/hotel.png</iconurl></primarycategory><address>Freyova 942/35</address><city>Prague</city><state>Czech Republic</state><geolat>50.1063156</geolat><geolong>14.5026057</geolong></venue><user><id>920173</id><firstname>Radek</firstname><lastname>Bednarik</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/HG5UD3RYQDPY5DQ1.jpg</photo><gender>male</gender></user><display>Radek B. @ Galerie Fenix</display><ping>true</ping></checkin><checkin><id>42556222</id><created>Wed, 12 May 10 10:27:28 +0000</created><timezone>Europe/Prague</timezone><ismayor>true</ismayor><venue><id>1052635</id><name>Televizní klub Rohlík</name><primarycategory><id>79170</id><fullpathname>Nightlife:Pub</fullpathname><nodename>Pub</nodename><iconurl>http://foursquare.com/img/categories/nightlife/default.png</iconurl></primarycategory><address>Na Hřebenech II.</address><crossstreet>Na Klaudiánce</crossstreet><city>Praha</city><state>Czech Republic</state><geolat>50.05124214597198</geolat><geolong>14.42831039428711</geolong><phone>420261137426</phone></venue><user><id>133156</id><firstname>Eliška</firstname><lastname>Hutníková</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/1ES5ONX5MCKTNBOG.jpg</photo><gender>female</gender></user><display>Eliška H. @ Televizní klub Rohlík</display><ping>true</ping></checkin><checkin><id>42550054</id><created>Wed, 12 May 10 10:05:29 +0000</created><timezone>Europe/Prague</timezone><ismayor>true</ismayor><venue><id>2398235</id><name>Vos a spse</name><primarycategory><id>79017</id><fullpathname>College &amp; Education:High School</fullpathname><nodename>High School</nodename><iconurl>http://foursquare.com/img/categories/education/default.png</iconurl></primarycategory><address>koterovská 85</address><city>Plzeň</city><state>Česka republika</state><geolat>49.7329963</geolat><geolong>13.403608</geolong></venue><user><id>863937</id><firstname>Pavel</firstname><lastname>Praizler</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/C3UHUQKGEO5L4CPE.jpg</photo><gender>male</gender></user><display>Pavel P. @ Vos a spse</display><ping>false</ping></checkin><checkin><id>42538801</id><created>Wed, 12 May 10 09:19:10 +0000</created><timezone>Europe/Prague</timezone><venue><id>3671605</id><name>Potraviny</name><address>Komořanská 2168</address><crossstreet>Okružní</crossstreet><city>Praha</city><state>Česká republika</state><zip>14300</zip><geolat>49.9909024</geolat><geolong>14.409704</geolong></venue><user><id>310591</id><firstname>Jiří</firstname><lastname>Mašek</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/YF05MKWCSCL1KLYB.jpg</photo><gender>male</gender></user><display>Jiří M. @ Potraviny</display><ping>false</ping></checkin><checkin><id>42518346</id><created>Wed, 12 May 10 07:44:41 +0000</created><timezone>Europe/Prague</timezone><venue><id>1403007</id><name>Pošta Bory</name><primarycategory><id>96354</id><fullpathname>Home / Work / Other:Post Office</fullpathname><nodename>Post Office</nodename><iconurl>http://foursquare.com/img/categories/building/default.png</iconurl></primarycategory><address>Klatovská třída 127</address><city>Česká republika</city><state>Plzeň</state><geolat>49.72717020644723</geolat><geolong>13.36735725402832</geolong></venue><user><id>453458</id><firstname>Viktor</firstname><lastname>Podlipský</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/YWIWMZDEQICML1MS.jpg</photo><gender>male</gender></user><display>Viktor P. @ Pošta Bory</display><ping>false</ping></checkin><checkin><id>42509047</id><created>Wed, 12 May 10 07:06:43 +0000</created><timezone>Europe/Prague</timezone><ismayor>true</ismayor><venue><id>939545</id><name>Filmove ateliery Barrandov</name><primarycategory><id>79140</id><fullpathname>Home / Work / Other:Other - Buildings</fullpathname><nodename>Other - Buildings</nodename><iconurl>http://foursquare.com/img/categories/building/default.png</iconurl></primarycategory><address>Kříženeckého náměstí 322</address><city>Praha</city><state>Česká republika</state><zip>15233</zip><geolat>50.0305849</geolat><geolong>14.3912062</geolong></venue><user><id>226248</id><firstname>Radek</firstname><lastname>Wrana</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/XJZLLYRAMDWHWNAB.jpg</photo><gender>male</gender></user><display>Radek W. @ Filmove ateliery Barrandov</display><ping>true</ping></checkin><checkin><id>42494918</id><created>Wed, 12 May 10 06:12:29 +0000</created><timezone>Europe/Prague</timezone><ismayor>true</ismayor><venue><id>368524</id><name>TO2</name><primarycategory><id>79115</id><fullpathname>Home / Work / Other:Corporate / Office</fullpathname><nodename>Corporate / Office</nodename><iconurl>http://foursquare.com/img/categories/building/default.png</iconurl></primarycategory><address>Vyskocilova</address><city>Prague</city><state>Czech Republic</state><geolat>50.04840379003272</geolat><geolong>14.457192420959473</geolong></venue><user><id>1019498</id><firstname>Honza</firstname><lastname>Klívar</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/QBVARJJJXHZDSR05.jpg</photo><gender>male</gender></user><display>Honza K. @ TO2</display><ping>true</ping></checkin><checkin><id>42361733</id><created>Wed, 12 May 10 00:26:44 +0000</created><timezone>Europe/Prague</timezone><user><id>88950</id><firstname>Matous</firstname><lastname>Petran</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/G10XY4XGHVR25QOP.png</photo><gender>male</gender></user><display>Matous P. @ [off the grid]</display><ping>true</ping></checkin><checkin><id>42261463</id><created>Tue, 11 May 10 21:15:44 +0000</created><timezone>Europe/Prague</timezone><ismayor>true</ismayor><venue><id>894191</id><name>Klub 011 Strahov</name><primarycategory><id>79153</id><fullpathname>Nightlife:Bar</fullpathname><nodename>Bar</nodename><iconurl>http://foursquare.com/img/categories/nightlife/default.png</iconurl></primarycategory><address>Chaloupeckého</address><city>Prague</city><state>Czech Republic</state><geolat>50.08041511915279</geolat><geolong>14.395694732666016</geolong></venue><user><id>89157</id><firstname>Tomáš</firstname><lastname>Kápl</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/JPZSXAOWGQTXB4QG.jpg</photo><gender>male</gender></user><display>Tomáš K. @ Klub 011 Strahov</display><ping>true</ping></checkin><checkin><id>42215446</id><created>Tue, 11 May 10 19:24:39 +0000</created><timezone>Europe/Prague</timezone><venue><id>192527</id><name>Synot Tip Aréna</name><address>U Slavie 1540/2a</address><city>Prague 10</city><state>Czech Republic</state><zip>100 00</zip><geolat>50.067442361596015</geolat><geolong>14.47148323059082</geolong></venue><user><id>345893</id><firstname>Petr</firstname><lastname>Koncal</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/VLIYT4HTSTUW10WP.jpg</photo><gender>male</gender></user><display>Petr K. @ Synot Tip Aréna</display><ping>true</ping></checkin><checkin><id>42156217</id><created>Tue, 11 May 10 17:14:20 +0000</created><timezone>Europe/Prague</timezone><venue><id>1154853</id><name>Schnirchova</name><address>Schnirchova 9</address><city>Praha</city><state>Česká republika</state><zip>17000</zip><geolat>50.10191</geolat><geolong>14.4350265</geolong></venue><user><id>374495</id><firstname>Lukas</firstname><lastname>Bartonek</lastname><photo>http://foursquare.com/img/blank_boy.png</photo><gender>male</gender></user><display>Lukas B. @ Schnirchova</display><ping>true</ping></checkin><checkin><id>42001313</id><created>Tue, 11 May 10 11:39:55 +0000</created><timezone>Europe/Prague</timezone><venue><id>1052635</id><name>Televizní klub Rohlík</name><primarycategory><id>79170</id><fullpathname>Nightlife:Pub</fullpathname><nodename>Pub</nodename><iconurl>http://foursquare.com/img/categories/nightlife/default.png</iconurl></primarycategory><address>Na Hřebenech II.</address><crossstreet>Na Klaudiánce</crossstreet><city>Praha</city><state>Czech Republic</state><geolat>50.05124214597198</geolat><geolong>14.42831039428711</geolong><phone>420261137426</phone></venue><user><id>341516</id><firstname>Martin</firstname><lastname>Hassman</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/ZHMR5TKJKHFNRN4P.png</photo><gender>male</gender></user><display>Martin H. @ Televizní klub Rohlík</display><ping>true</ping></checkin><checkin><id>41996268</id><created>Tue, 11 May 10 11:25:52 +0000</created><timezone>Europe/Prague</timezone><venue><id>3643127</id><name>Restaurace Baifu</name><primarycategory><id>79051</id><fullpathname>Food:Chinese</fullpathname><nodename>Chinese</nodename><iconurl>http://foursquare.com/img/categories/food/default.png</iconurl></primarycategory><address>Za Brumlovkou 266/2</address><city>Praha</city><state>CZ</state><zip>14000</zip><geolat>50.0465456</geolat><geolong>14.4564696</geolong><phone>420241404177</phone></venue><user><id>392325</id><firstname>Lukáš</firstname><lastname>Jirovský</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/TBW1D0X312FGBT1M.jpg</photo><gender>male</gender></user><display>Lukáš J. @ Restaurace Baifu</display><ping>true</ping></checkin><checkin><id>41986220</id><created>Tue, 11 May 10 10:55:45 +0000</created><timezone>Europe/Prague</timezone><venue><id>238358</id><name>ČVUT FEL</name><primarycategory><id>79037</id><fullpathname>College &amp; Education:University</fullpathname><nodename>University</nodename><iconurl>http://foursquare.com/img/categories/education/default.png</iconurl></primarycategory><address>Technická 2</address><city>Praha</city><state>Česká republika</state><zip>16000</zip><geolat>50.1025636</geolat><geolong>14.3923173</geolong></venue><user><id>493025</id><firstname>Vašek</firstname><lastname>Purchart</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/J1NAQKKLLA55WTCH.png</photo><gender>male</gender></user><display>Vašek P. @ ČVUT FEL</display><ping>true</ping></checkin><checkin><id>41958265</id><created>Tue, 11 May 10 08:58:09 +0000</created><timezone>Europe/Prague</timezone><venue><id>263592</id><name>Metro =A= Dejvická</name><primarycategory><id>79282</id><fullpathname>Travel:Subway</fullpathname><nodename>Subway</nodename><iconurl>http://foursquare.com/img/categories/travel/subway.png</iconurl></primarycategory><address>Vítězné náměstí</address><city>Praha</city><state>Česká Republika</state><zip>16000</zip><geolat>50.10051458137106</geolat><geolong>14.393677711486816</geolong></venue><user><id>352985</id><firstname>alena</firstname><lastname>varkockova</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/NIDXPXCOZQQJDIMR.jpg</photo><gender>female</gender></user><display>alena v. @ Metro =A= Dejvická</display><ping>true</ping></checkin><checkin><id>41935835</id><created>Tue, 11 May 10 07:11:36 +0000</created><timezone>Europe/Prague</timezone><venue><id>768607</id><name>Libeňský most</name><primarycategory><id>96356</id><fullpathname>Parks &amp; Outdoors:Bridge</fullpathname><nodename>Bridge</nodename><iconurl>http://foursquare.com/img/categories/parks_outdoors/default.png</iconurl></primarycategory><address>Libeňský most</address><city>Prague</city><state>Prague</state><zip>180 00</zip><geolat>50.1034533</geolat><geolong>14.4664392</geolong></venue><user><id>154949</id><firstname>Daniel</firstname><lastname>Dočekal</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/UW4JBEWL2SCY3IEX.jpg</photo><gender>male</gender></user><display>Daniel D. @ Libeňský most</display><ping>true</ping></checkin><checkin><id>41572041</id><created>Mon, 10 May 10 16:18:16 +0000</created><timezone>Europe/Prague</timezone><ismayor>true</ismayor><venue><id>1658892</id><name>Libeňská</name><address></address><city></city><state></state><geolat>50.136988</geolat><geolong>14.430364</geolong></venue><user><id>513848</id><firstname>Vladimír</firstname><lastname>Mráz</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/OQYDWNRDL0QQTDOD.jpg</photo><gender>male</gender></user><display>Vladimír M. @ Libeňská</display><ping>true</ping></checkin><checkin><id>41406391</id><created>Mon, 10 May 10 08:42:01 +0000</created><timezone>Europe/Prague</timezone><venue><id>1265458</id><name>Pivní záležitost</name><primarycategory><id>79170</id><fullpathname>Nightlife:Pub</fullpathname><nodename>Pub</nodename><iconurl>http://foursquare.com/img/categories/nightlife/default.png</iconurl></primarycategory><address>Biskupcova 19</address><city>Praha</city><state>Hlavní město Praha</state><geolat>50.089823</geolat><geolong>14.4699847</geolong></venue><user><id>553159</id><firstname>Lukáš</firstname><lastname>Kratochvíl</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/ZZBSCCEDGOHFUNSH.jpg</photo><gender>male</gender></user><display>Lukáš K. @ Pivní záležitost</display><ping>true</ping></checkin><checkin><id>40988366</id><created>Sun, 09 May 10 14:06:59 +0000</created><timezone>Europe/Prague</timezone><shout>:(</shout><venue><id>1003012</id><name>Olympia Plzeň</name><primarycategory><id>79242</id><fullpathname>Shops:Mall</fullpathname><nodename>Mall</nodename><iconurl>http://foursquare.com/img/categories/shops/default.png</iconurl></primarycategory><address>Písecká 972/1</address><crossstreet>Nepomucká</crossstreet><city>Plzeň</city><state>Česká republika</state><zip>32600</zip><geolat>49.7010597</geolat><geolong>13.4258471</geolong></venue><user><id>870358</id><firstname>Jan</firstname><lastname>Toms</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/AG14TQPJB3NRP543.jpg</photo><gender>male</gender></user><display>Jan T. @ Olympia Plzeň</display><ping>false</ping></checkin><checkin><id>40525458</id><created>Sat, 08 May 10 18:11:11 +0000</created><timezone>Europe/Prague</timezone><shout>Na Libuši s Tereskou</shout><venue><id>1357561</id><name>Narodni divadlo</name><primarycategory><id>78987</id><fullpathname>Arts &amp; Entertainment:Performing Arts:Theater</fullpathname><nodename>Theater</nodename><iconurl>http://foursquare.com/img/categories/arts_entertainment/default.png</iconurl></primarycategory><address></address><city></city><state></state><geolat>50.081402</geolat><geolong>14.413476</geolong></venue><user><id>348204</id><firstname>Ondra</firstname><lastname>Macoszek</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/CEM1TKBNOLOD42BA.jpg</photo><gender>male</gender></user><display>Ondra M. @ Narodni divadlo</display><ping>true</ping></checkin><checkin><id>39791851</id><created>Fri, 07 May 10 13:47:24 +0000</created><timezone>Europe/Prague</timezone><venue><id>531243</id><name>DOX Center for Contemporary Art</name><primarycategory><id>78960</id><fullpathname>Arts &amp; Entertainment:Art Gallery</fullpathname><nodename>Art Gallery</nodename><iconurl>http://foursquare.com/img/categories/arts_entertainment/artgallery.png</iconurl></primarycategory><address>Poupětova 1</address><city>Prague</city><state>Czech republic</state><zip>17000</zip><geolat>50.1067813</geolat><geolong>14.4470411</geolong><phone>420774145434</phone><twitter>doxprague</twitter></venue><user><id>89285</id><firstname>František</firstname><lastname>Hába</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/89285_1257439071114.png</photo><gender>male</gender></user><display>František H. @ DOX Center for Contemporary Art</display><ping>true</ping></checkin><checkin><id>39185009</id><created>Thu, 06 May 10 12:29:39 +0000</created><timezone>Europe/Prague</timezone><venue><id>1018114</id><name>Menza Italská</name><primarycategory><id>79081</id><fullpathname>Food:Pizza</fullpathname><nodename>Pizza</nodename><iconurl>http://foursquare.com/img/categories/food/pizza.png</iconurl></primarycategory><address></address><city></city><state></state><geolat>50.08283851488614</geolat><geolong>14.440197944641113</geolong></venue><user><id>733527</id><firstname>Martin</firstname><lastname>Sova</lastname><photo>http://foursquare.com/img/blank_boy.png</photo><gender>male</gender></user><display>Martin S. @ Menza Italská</display><ping>true</ping></checkin><checkin><id>37452093</id><created>Sun, 02 May 10 19:26:15 +0000</created><timezone>Europe/Prague</timezone><venue><id>192508</id><name>Prague-Ruzyně Airport (PRG)</name><primarycategory><id>79261</id><fullpathname>Travel:Airport</fullpathname><nodename>Airport</nodename><iconurl>http://foursquare.com/img/categories/travel/airport.png</iconurl></primarycategory><address>Letiště Praha - Ruzyně</address><city>Prague</city><state>Czech Republic</state><zip>160 08</zip><geolat>50.1062712</geolat><geolong>14.2700968</geolong></venue><user><id>700147</id><firstname>Petr</firstname><lastname>Stránský</lastname><photo>http://foursquare.com/img/blank_boy.png</photo><gender>male</gender></user><display>Petr S. @ Prague-Ruzyně Airport (PRG)</display><ping>true</ping></checkin><checkin><id>36442794</id><created>Fri, 30 Apr 10 22:09:07 +0000</created><timezone>Europe/Prague</timezone><venue><id>236204</id><name>COMO restaurant</name><primarycategory><id>79106</id><fullpathname>Food:Tapas</fullpathname><nodename>Tapas</nodename><iconurl>http://foursquare.com/img/categories/food/default.png</iconurl></primarycategory><address>Václavské nám. 45</address><city>Praha</city><state>Česká Republika</state><zip>11000</zip><geolat>50.08110359630795</geolat><geolong>14.428482055664062</geolong><phone>420222247240</phone><twitter>ComoRestaurant</twitter></venue><user><id>119017</id><firstname>Milos</firstname><photo>http://foursquare.com/img/blank_boy.png</photo><gender>male</gender></user><display>Milos @ COMO restaurant</display><ping>true</ping></checkin><checkin><id>30209182</id><created>Sun, 18 Apr 10 10:57:02 +0000</created><timezone>Europe/Prague</timezone><shout>brunch full monty</shout><venue><id>383452</id><name>Bohemia bagel - Praha 7</name><primarycategory><id>114946</id><fullpathname>Food:Bagels</fullpathname><nodename>Bagels</nodename><iconurl>http://foursquare.com/img/categories/food/default.png</iconurl></primarycategory><address>Dukelsych hrdinu 48</address><city>Prague 7</city><state>Czech Republic</state><geolat>50.102827</geolat><geolong>14.4326883</geolong><phone>420224812560</phone></venue><user><id>181991</id><firstname>Markéta</firstname><lastname>Jančarová</lastname><photo>http://foursquare.com/img/blank_girl.png</photo><gender>female</gender></user><display>Markéta J. @ Bohemia bagel - Praha 7</display><ping>true</ping></checkin><checkin><id>26263202</id><created>Fri, 09 Apr 10 16:27:56 +0000</created><timezone>Europe/Prague</timezone><venue><id>1074265</id><name>Café Pavlač</name><primarycategory><id>79049</id><fullpathname>Food:Café</fullpathname><nodename>Café</nodename><iconurl>http://foursquare.com/img/categories/food/cafe.png</iconurl></primarycategory><address>Víta Nejedlého 22</address><crossstreet>Seifertova</crossstreet><city>Praha 3</city><state>ČR</state><zip>130 00</zip><geolat>50.0838242</geolat><geolong>14.4490934</geolong><phone>420222721731</phone></venue><user><id>98838</id><firstname>Jan</firstname><lastname>Patawa</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/XZCQQPV4O3AFHGHZ.jpg</photo><gender>male</gender></user><display>Jan P. @ Café Pavlač</display><ping>true</ping></checkin><checkin><id>16913638</id><created>Sun, 14 Mar 10 17:13:18 +0000</created><timezone>Europe/Prague</timezone><venue><id>1054997</id><name>Metro =C= Chodov</name><primarycategory><id>79282</id><fullpathname>Travel:Subway</fullpathname><nodename>Subway</nodename><iconurl>http://foursquare.com/img/categories/travel/subway.png</iconurl></primarycategory><address>Roztylská</address><city>Praha</city><state>Česká Republika</state><zip>120 00</zip><geolat>50.03090148015986</geolat><geolong>14.491739273071289</geolong></venue><user><id>403354</id><firstname>Marek</firstname><lastname>Paris</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/TKQ1ZSHKY1KVLKJD.jpg</photo><gender>male</gender></user><display>Marek P. @ Metro =C= Chodov</display><ping>true</ping></checkin><checkin><id>13066911</id><created>Sat, 27 Feb 10 12:42:10 +0000</created><timezone>Europe/Prague</timezone><venue><id>1347037</id><name>Řitka</name><address>Středočeský kraj</address><city>Řitka</city><state>Czech Republic</state><geolat>49.8943367</geolat><geolong>14.3007612</geolong></venue><user><id>414989</id><firstname>Jan</firstname><lastname>Cermak</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/SOEBB2F04OB23BIR.jpg</photo><gender>male</gender></user><display>Jan C. @ Řitka</display><ping>true</ping></checkin></checkins> ");
            }
            else
            {
                xml = Downloader.ProcessRequest(URL_CHECKINS, Downloader.METHOD_GET, parameters, this.username, this.password);
            }

            XmlNode checkins = xml.GetElementsByTagName("checkins")[0];

            List<Checkin> list = new List<Checkin>();

            for (int i = 0; i < checkins.ChildNodes.Count; i++)
			{
                list.Add(new Checkin(checkins.ChildNodes[i]));
			}

            return list;
        }

        /// <summary>
        /// Allows you to check-in to a place.
        /// </summary>
        /// <param name="vid">ID of the venue where you want to check-in</param>
        /// <returns></returns>
        public Checkin checkin(string vid)
        {
            return checkin(vid, null, null, false, true, false, false, null, null);
        }

        /// <summary>
        /// Allows you to check-in to a place.
        /// </summary>
        /// <param name="vid">ID of the venue where you want to check-in</param>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns></returns>
        public Checkin checkin(string vid, string geolat, string geolong)
        {
            return checkin(vid, null, null, false, true, false, false, geolat, geolong);
        }

        /// <summary>
        /// Allows you to check-in to a place.
        /// </summary>
        /// <param name="vid">ID of the venue where you want to check-in</param>
        /// <param name="shout">message about the check-in</param>
        /// <returns></returns>
        public Checkin checkin(string vid, string shout)
        {
            return checkin(vid, null, shout, false, true, false, false, null, null);
        }

        /// <summary>
        /// Allows you to check-in to a place.
        /// </summary>
        /// <param name="vid">ID of the venue where you want to check-in</param>
        /// <param name="shout">message about the check-in</param>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns></returns>
        public Checkin checkin(string vid, string shout, string geolat, string geolong)
        {
            return checkin(vid, null, shout, false, true, false, false, geolat, geolong);
        }

        /// <summary>
        /// Allows you to check-in to a place.
        /// </summary>
        /// <param name="vid">ID of the venue where you want to check-in</param>
        /// <param name="venue">venue name</param>
        /// <param name="shout">message about the check-in</param>
        /// <param name="prvt"></param>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns></returns>
        public Checkin checkin(string vid, string venue, string shout, bool prvt, string geolat, string geolong)
        {
            return checkin(vid, venue, shout, prvt, true, false, false, geolat, geolong);
        }

        /// <summary>
        /// Allows you to check-in to a place.
        /// </summary>
        /// <param name="vid">ID of the venue where you want to check-in</param>
        /// <param name="venue">venue name</param>
        /// <param name="shout">message about the check-in</param>
        /// <param name="prvt"></param>
        /// <param name="twitter"></param>
        /// <param name="facebook"></param>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns></returns>
        public Checkin checkin(string vid, string venue, string shout, bool prvt, bool twitter, bool facebook, string geolat, string geolong)
        {
            return checkin(vid, venue, shout, prvt, false, twitter, facebook, geolat, geolong);
        }

        /// <summary>
        /// Allows you to check-in to a place.
        /// </summary>
        /// <param name="vid">ID of the venue where you want to check-in</param>
        /// <param name="shout">message about the check-in</param>
        /// <param name="prvt"></param>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns></returns>
        public Checkin checkin(string vid, string shout, bool prvt, string geolat, string geolong)
        {
            return checkin(vid, null, shout, prvt, true, false, false, geolat, geolong);
        }

        /// <summary>
        /// Allows you to check-in to a place.
        /// </summary>
        /// <param name="vid">ID of the venue where you want to check-in</param>
        /// <param name="shout">message about the check-in</param>
        /// <param name="prvt"></param>
        /// <param name="twitter"></param>
        /// <param name="facebook"></param>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns></returns>
        public Checkin checkin(string vid, string shout, bool prvt, bool twitter, bool facebook, string geolat, string geolong)
        {
            return checkin(vid, null, shout, prvt, false, twitter, facebook, geolat, geolong);
        }

        /// <summary>
        /// Allows you to check-in to a place.
        /// </summary>
        /// <param name="vid">ID of the venue where you want to check-in</param>
        /// <param name="venue">venue name</param>
        /// <param name="shout">message about the check-in</param>
        /// <param name="prvt"></param>
        /// <param name="dflt"></param>
        /// <param name="twitter"></param>
        /// <param name="facebook"></param>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns></returns>
        private Checkin checkin(string vid, string venue, string shout, bool prvt, bool dflt, bool twitter, bool facebook, string geolat, string geolong)
        {
            string parameters = "";

            if (!String.IsNullOrEmpty(vid))
            {
                parameters = "vid=" + vid;
            }
            else if (!String.IsNullOrEmpty(venue))
            {
                parameters = "venue=" + HttpUtility.UrlEncode(venue);
            }

            if (!String.IsNullOrEmpty(shout))
            {
                if (shout.Length > 140)
                {
                    throw new IOException("Shout too long!");
                }

                parameters += String.IsNullOrEmpty(parameters) ? "shout=" + HttpUtility.UrlEncode(shout) : "&shout=" + HttpUtility.UrlEncode(shout);
            }

            if (String.IsNullOrEmpty(parameters))
            {
                throw new IOException("Venue or ID of the Venue or Shout must be setted.");
            }

            if (prvt) {
                parameters += "&private=1";
            }

            if (!dflt)
            {
                parameters += twitter ? "&twitter=1" : "&twitter=0";
                parameters += facebook ? "&facebook=1" : "&facebook=0";
            }

            if (!String.IsNullOrEmpty(geolat) && !String.IsNullOrEmpty(geolong))
            {
                parameters += "&geolat=" + geolat;
                parameters += "&geolong=" + geolong;
            }
            
            XmlDocument xml = Downloader.ProcessRequest(URL_CHECK_IN, Downloader.METHOD_POST, parameters, this.username, this.password);

            XmlNode checkin = xml.GetElementsByTagName("checkin")[0];

            return new Checkin(checkin);
        }

        /// <summary>
        /// Allows broadcast a message to friends.
        /// </summary>
        /// <param name="shout">message to friends</param>
        /// <returns></returns>
        public Checkin shout(string shout)
        {
            return checkin(null, null, shout, false, true, false, false, null, null);
        }

        /// <summary>
        /// Allows broadcast a message to friends.
        /// </summary>
        /// <param name="shout">message to friends</param>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns></returns>
        public Checkin shout(string shout, string geolat, string geolong)
        {
            return checkin(null, null, shout, false, true, false, false, geolat, geolong);
        }

        /// <summary>
        /// Allows broadcast a message to friends.
        /// </summary>
        /// <param name="shout">message to friends</param>
        /// <param name="twitter"></param>
        /// <param name="facebook"></param>
        /// <returns></returns>
        public Checkin shout(string shout, bool twitter, bool facebook)
        {
            return checkin(null, null, shout, false, false, twitter, facebook, null, null);
        }

        /// <summary>
        /// Allows broadcast a message to friends.
        /// </summary>
        /// <param name="shout">message to friends</param>
        /// <param name="twitter"></param>
        /// <param name="facebook"></param>
        /// <param name="geolat"></param>
        /// <param name="geolong"></param>
        /// <returns></returns>
        private Checkin shout(string shout, bool twitter, bool facebook, string geolat, string geolong)
        {
            return checkin(null, null, shout, false, false, twitter, facebook, geolat, geolong);
        }

        /// <summary>
        /// Returns a history of checkins for the authenticated user.
        /// </summary>
        /// <returns>Returns a history of checkins for the authenticated user.</returns>
        public List<Checkin> getHistory()
        {
            return getHistory(20,  null);
        }

        /// <summary>
        /// Returns a history of checkins for the authenticated user.
        /// </summary>
        /// <param name="limit">number of checkins to return (default: 20, max: 250)</param>
        /// <returns>Returns a history of checkins for the authenticated user.</returns>
        public List<Checkin> getHistory(int limit)
        {
            return getHistory(limit, null);
        }

        /// <summary>
        /// Returns a history of checkins for the authenticated user.
        /// </summary>
        /// <param name="sinceid">id to start returning results from</param>
        /// <returns>Returns a history of checkins for the authenticated user.</returns>
        public List<Checkin> getHistory(string sinceid)
        {
            return getHistory(0, sinceid);
        }

        /// <summary>
        /// Returns a history of checkins for the authenticated user.
        /// </summary>
        /// <param name="limit">number of checkins to return (default: 20, max: 250)</param>
        /// <param name="sinceid">id to start returning results from</param>
        /// <returns>Returns a history of checkins for the authenticated user.</returns>
        public List<Checkin> getHistory(int limit, string sinceid)
        {
            string parameters = "";

            if (limit > 0)
            {
                parameters += "l=" + limit;
            }

            if (!String.IsNullOrEmpty(sinceid))
            {
                parameters += String.IsNullOrEmpty(parameters) ? "sinceid=" + sinceid : "&sinceid=" + sinceid;
            }

            XmlDocument xml = Downloader.ProcessRequest(URL_HISTORY, Downloader.METHOD_GET, parameters, this.username, this.password);

            XmlNode checkins = xml.GetElementsByTagName("checkins")[0];

            List<Checkin> list = new List<Checkin>();

            for (int i = 0; i < checkins.ChildNodes.Count; i++)
            {
                list.Add(new Checkin(checkins.ChildNodes[i]));
            }

            return list;
        }
        

        ////////////////////////////////////////////////////////////////////////
        /// USER METHODS ///////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Load profile information for the authenticated user.
        /// </summary>
        /// <returns></returns>
        public User getUserDetail()
        {
            return getUserDetail(null, false, false);
        }

        /// <summary>
        /// Load profile information for a given user.
        /// </summary>
        /// <param name="uid">userid for the user whose information you want to retrieve</param>
        /// <returns></returns>
        public User getUserDetail(string uid)
        {
            return getUserDetail(uid, false, false);
        }

        /// <summary>
        /// Load profile information for the authenticated user.
        /// </summary>
        /// <param name="badges">get also badges for this user</param>
        /// <param name="mayor">get also venues for which this user is a mayor</param>
        /// <returns></returns>
        public User getUserDetail(bool badges, bool mayor)
        {
            return getUserDetail(null, badges, mayor);
        }

        /// <summary>
        /// Load profile information for a given user.
        /// </summary>
        /// <param name="uid">userid for the user whose information you want to retrieve</param>
        /// <param name="badges">get also badges for this user</param>
        /// <param name="mayor">get also venues for which this user is a mayor</param>
        /// <returns></returns>
        public User getUserDetail(string uid, bool badges, bool mayor)
        {
            string parameters = "";

            if (!String.IsNullOrEmpty(uid))
            {
                parameters += "uid=" + uid;
            }

            if (badges)
            {
                parameters += String.IsNullOrEmpty(parameters) ? "badges=1" : "&badges=1";
            }

            if (mayor)
            {
                parameters += String.IsNullOrEmpty(parameters) ? "mayor=1" : "&mayor=1";
            }

            XmlDocument xml;

            if (this.debug)
            {
                xml = Downloader.stringToXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><user><id>310591</id><firstname>Jiří</firstname><lastname>Mašek</lastname><photo>http://playfoursquare.s3.amazonaws.com/userpix_thumbs/YF05MKWCSCL1KLYB.jpg</photo><gender>male</gender><phone>420728189543</phone><email>masekj@gmail.com</email><twitter>jirik8887</twitter><facebook>692058649</facebook><settings><pings>off</pings><sendtotwitter>false</sendtotwitter><sendtofacebook>true</sendtofacebook></settings><status><friendrequests>0</friendrequests></status><checkin><id>43158416</id><created>Thu, 13 May 10 10:26:05 +0000</created><timezone>Europe/Prague</timezone><ismayor>true</ismayor><venue><id>1002025</id><name>ČVUT FEL</name><primarycategory><id>79037</id><fullpathname>College &amp; Education:University</fullpathname><nodename>University</nodename><iconurl>http://foursquare.com/img/categories/education/default.png</iconurl></primarycategory><address>Karlovo náměstí 13</address><crossstreet>Resslova</crossstreet><city>Prague</city><state>Czech republic</state><zip>12800</zip><geolat>50.07671094236536</geolat><geolong>14.41805362701416</geolong></venue><display>Jiří M. @ ČVUT FEL</display></checkin><badges><badge><id>1</id><name>Newbie</name><icon>http://foursquare.com/img/badge/newbie.png</icon><description>Congrats on your first check-in!</description></badge><badge><id>2</id><name>Adventurer</name><icon>http://foursquare.com/img/badge/adventurer.png</icon><description>You've checked into 10 different venues!</description></badge><badge><id>3</id><name>Explorer</name><icon>http://foursquare.com/img/badge/explorer.png</icon><description>You've checked into 25 different venues!</description></badge><badge><id>4</id><name>Superstar</name><icon>http://foursquare.com/img/badge/superstar.png</icon><description>You've checked into 50 different venues!</description></badge><badge><id>5</id><name>Bender</name><icon>http://foursquare.com/img/badge/bender.png</icon><description>That's 4+ nights in a row for you!</description></badge><badge><id>6</id><name>Crunked</name><icon>http://foursquare.com/img/badge/crunked.png</icon><description>That's 4+ stops in one night for you!</description></badge><badge><id>7</id><name>Local</name><icon>http://foursquare.com/img/badge/local.png</icon><description>You've been at the same place 3x in one week!</description></badge><badge><id>8</id><name>Super User</name><icon>http://foursquare.com/img/badge/superuser.png</icon><description>That's 30 checkins in a month for you!</description></badge><badge><id>13</id><name>Photogenic</name><icon>http://foursquare.com/img/badge/photogenic.png</icon><description>You found 3 places with a photobooth!</description></badge><badge><id>32</id><name>Overshare</name><icon>http://foursquare.com/img/badge/overshare.png</icon><description>10+ checkins in 12 hours! Next up: tweeting that you unlocked this Overshare badge?</description></badge><badge><id>75</id><name>Zoetrope</name><icon>http://foursquare.com/img/badge/movie.png</icon><description>That brings you to 10 movie theater checkins! Now, can you pick us up a large popcorn while you're up?</description></badge><badge><id>79</id><name>Babysitter</name><icon>http://foursquare.com/img/badge/playground.png</icon><description>Forget those &quot;Bender&quot; and &quot;Crunked&quot; badges - you've conquered the playground circuit! (10 checkins!)</description></badge><badge><id>80</id><name>Swarm</name><icon>http://foursquare.com/img/badge/swarm.png</icon><description>50+ people are also checked-in here - it's a foursquare flashmob!</description></badge><badge><id>83</id><name>Super Mayor</name><icon>http://foursquare.com/img/badge/supermayor.png</icon><description>A special shoutout for holding down 10 mayorships at once!</description></badge><badge><id>84</id><name>I'm on a boat!</name><icon>http://foursquare.com/img/badge/boat.png</icon><description>♫ This ain't Seaworld, this is as real as it gets / I'm on a boat, MF'er, don't you ever forget! ♫</description></badge><badge><id>134</id><name>Barista</name><icon>http://foursquare.com/img/badge/barista.png</icon><description>Congrats - you've checked in at 5 different Starbucks! Be sure to pick up a double tall latte for your friend - I'm sure they'd do the same for you.</description></badge><badge><id>144</id><name>#4sqDay 2010</name><icon>http://foursquare.com/img/badge/4sqday.png</icon><description>Happy foursquare day! (four squared = 4/16, get it?) Here's a toast to all of you for making foursquare so amazing and to the 150+ #4sqDay parties going on around the world!</description></badge></badges><mayor><venue><id>1261094</id><name>Albert</name><primarycategory><id>79235</id><fullpathname>Shops:Food &amp; Drink:Grocery / Supermarket</fullpathname><nodename>Grocery / Supermarket</nodename><iconurl>http://foursquare.com/img/categories/shops/food_grocery.png</iconurl></primarycategory><address>Karlovo náměstí 15</address><crossstreet>Resslova</crossstreet><city>Praha</city><state>Česká republika</state><zip>12000</zip><geolat>50.0768044</geolat><geolong>14.419123</geolong></venue><venue><id>263763</id><name>Albertov</name><primarycategory><id>79193</id><fullpathname>Parks &amp; Outdoors:Other - Parks &amp; Outdoor</fullpathname><nodename>Other - Parks &amp; Outdoor</nodename><iconurl>http://foursquare.com/img/categories/parks_outdoors/default.png</iconurl></primarycategory><address>Albertov</address><city>Praha</city><state>Hlavní město Praha</state><zip>128 00</zip><geolat>50.0686276</geolat><geolong>14.4229778</geolong></venue><venue><id>1224150</id><name>Baťa</name><primarycategory><id>79212</id><fullpathname>Shops:Apparel:Shoes</fullpathname><nodename>Shoes</nodename><iconurl>http://foursquare.com/img/categories/shops/apparel.png</iconurl></primarycategory><address>Václavské náměstí 774/6</address><crossstreet>28. října</crossstreet><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.0836488</geolat><geolong>14.423851</geolong></venue><venue><id>192381</id><name>C&amp;A</name><primarycategory><id>79208</id><fullpathname>Shops:Apparel</fullpathname><nodename>Apparel</nodename><iconurl>http://foursquare.com/img/categories/shops/apparel.png</iconurl></primarycategory><address>Václavské námestí 33</address><city>Prague</city><state>Czech Republic</state><zip>110 00</zip><geolat>50.0820332</geolat><geolong>14.4278495</geolong></venue><venue><id>845410</id><name>Costa Coffee</name><primarycategory><id>79049</id><fullpathname>Food:Café</fullpathname><nodename>Café</nodename><iconurl>http://foursquare.com/img/categories/food/cafe.png</iconurl></primarycategory><address>Vinohradská 151</address><crossstreet>Jičínská</crossstreet><city>Praha</city><state>Česká republika</state><zip>13000</zip><geolat>50.0788673</geolat><geolong>14.4611481</geolong></venue><venue><id>914182</id><name>CrossCafe</name><primarycategory><id>79049</id><fullpathname>Food:Café</fullpathname><nodename>Café</nodename><iconurl>http://foursquare.com/img/categories/food/cafe.png</iconurl></primarycategory><address>Anglické nábřeží 1</address><crossstreet>Pražská</crossstreet><city>Pilsen</city><state>Czech republic</state><zip>30100</zip><geolat>49.74603781764047</geolat><geolong>13.3828604221344</geolong></venue><venue><id>1384050</id><name>DM Drogerie</name><primarycategory><id>79222</id><fullpathname>Shops:Drug Store / Pharmacy</fullpathname><nodename>Drug Store / Pharmacy</nodename><iconurl>http://foursquare.com/img/categories/shops/drugstore.png</iconurl></primarycategory><address>Nádražní 32</address><crossstreet>U Královské louky</crossstreet><city>Praha</city><state>Česká republika</state><zip>15000</zip><geolat>50.061423022213496</geolat><geolong>14.409545660018921</geolong></venue><venue><id>2463799</id><name>Děkanát 1. LF UK v Praze</name><primarycategory><id>79001</id><fullpathname>College &amp; Education:Administrative Building</fullpathname><nodename>Administrative Building</nodename><iconurl>http://foursquare.com/img/categories/education/default.png</iconurl></primarycategory><address>Kateřinská 32</address><crossstreet>Ke Karlovu</crossstreet><city>Praha</city><state>Česká republika</state><zip>12800</zip><geolat>50.07458332110088</geolat><geolong>14.426625967025757</geolong></venue><venue><id>333969</id><name>IKEA</name><primarycategory><id>79225</id><fullpathname>Shops:Furniture / Home</fullpathname><nodename>Furniture / Home</nodename><iconurl>http://foursquare.com/img/categories/shops/default.png</iconurl></primarycategory><address>Skandinávská 1</address><city>Praha</city><state>Czech Republic</state><zip>15000</zip><geolat>50.05091147236599</geolat><geolong>14.299006462097168</geolong></venue><venue><id>909054</id><name>Kajetánka II</name><primarycategory><id>79014</id><fullpathname>College &amp; Education:Dorm</fullpathname><nodename>Dorm</nodename><iconurl>http://foursquare.com/img/categories/education/default.png</iconurl></primarycategory><address>Na Petynce 29</address><crossstreet>Na Zástřelu</crossstreet><city>Praha</city><state>Česká republika</state><zip>16200</zip><geolat>50.0880022</geolat><geolong>14.3708579</geolong></venue><venue><id>1666281</id><name>Lanová dráha na Petřín</name><primarycategory><id>79279</id><fullpathname>Travel:Other - Travel</fullpathname><nodename>Other - Travel</nodename><iconurl>http://foursquare.com/img/categories/travel/default.png</iconurl></primarycategory><address>Újezd</address><crossstreet>U Lanové dráhy</crossstreet><city>Praha</city><state>Česká republika</state><zip>11800</zip><geolat>50.08265951825522</geolat><geolong>14.40380573272705</geolong></venue><venue><id>1482887</id><name>Mangaloo Freshbar (I.P. Pavlova)</name><primarycategory><id>79071</id><fullpathname>Food:Juice Bar</fullpathname><nodename>Juice Bar</nodename><iconurl>http://foursquare.com/img/categories/food/default.png</iconurl></primarycategory><address>Jugoslávská 5</address><city>Praha 2</city><state>Hlavní město Praha</state><zip>120 00</zip><geolat>50.0754838</geolat><geolong>14.4311052</geolong></venue><venue><id>892470</id><name>McDonald's</name><primarycategory><id>79060</id><fullpathname>Food:Fast Food</fullpathname><nodename>Fast Food</nodename><iconurl>http://foursquare.com/img/categories/food/fastfood.png</iconurl></primarycategory><address>Vodičkova 15</address><crossstreet>Školská</crossstreet><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.0800134</geolat><geolong>14.4232678</geolong><phone>420224948839</phone></venue><venue><id>891384</id><name>Menza Arnošta z Pardubic</name><primarycategory><id>79012</id><fullpathname>College &amp; Education:Cafeteria</fullpathname><nodename>Cafeteria</nodename><iconurl>http://foursquare.com/img/categories/education/default.png</iconurl></primarycategory><address>Voršilská 1</address><crossstreet>Ostrovní</crossstreet><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.0804247</geolat><geolong>14.4167549</geolong></venue><venue><id>913675</id><name>Menza Kajetánka</name><primarycategory><id>79012</id><fullpathname>College &amp; Education:Cafeteria</fullpathname><nodename>Cafeteria</nodename><iconurl>http://foursquare.com/img/categories/education/default.png</iconurl></primarycategory><address>Radimova 12</address><crossstreet>Na Zástřelu</crossstreet><city>Praha</city><state>Česká republika</state><zip>16200</zip><geolat>50.0874534</geolat><geolong>14.3711454</geolong></venue><venue><id>3399444</id><name>Mini Market</name><primarycategory><id>79235</id><fullpathname>Shops:Food &amp; Drink:Grocery / Supermarket</fullpathname><nodename>Grocery / Supermarket</nodename><iconurl>http://foursquare.com/img/categories/shops/food_grocery.png</iconurl></primarycategory><address>Komořanská 2000/50</address><crossstreet>Na Homoli</crossstreet><city>Praha</city><state>Česká republika</state><zip>14300</zip><geolat>49.9901291</geolat><geolong>14.4094153</geolong></venue><venue><id>1844088</id><name>Mlýnská strouha</name><primarycategory><id>79191</id><fullpathname>Parks &amp; Outdoors:Lake / Pond</fullpathname><nodename>Lake / Pond</nodename><iconurl>http://foursquare.com/img/categories/parks_outdoors/default.png</iconurl></primarycategory><address>Pallova</address><crossstreet>Pražská</crossstreet><city>Plzeň</city><state>Česká republika</state><zip>30100</zip><geolat>49.74776403532779</geolat><geolong>13.381454944610596</geolong></venue><venue><id>1224565</id><name>New Yorker</name><primarycategory><id>79208</id><fullpathname>Shops:Apparel</fullpathname><nodename>Apparel</nodename><iconurl>http://foursquare.com/img/categories/shops/apparel.png</iconurl></primarycategory><address>Na příkopě 388/1</address><crossstreet>Na Můstku</crossstreet><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.0843405</geolat><geolong>14.4234634</geolong></venue><venue><id>1311272</id><name>Palackého náměstí</name><primarycategory><id>79196</id><fullpathname>Parks &amp; Outdoors:Plaza / Square</fullpathname><nodename>Plaza / Square</nodename><iconurl>http://foursquare.com/img/categories/parks_outdoors/default.png</iconurl></primarycategory><address>Palackého náměstí</address><crossstreet>Rašínovo nábřeží</crossstreet><city>Prague</city><state>Czech republic</state><geolat>50.0732431</geolat><geolong>14.4145411</geolong></venue><venue><id>1910873</id><name>Pasáž Světozor</name><primarycategory><id>79244</id><fullpathname>Shops:Other - Shopping</fullpathname><nodename>Other - Shopping</nodename><iconurl>http://foursquare.com/img/categories/shops/default.png</iconurl></primarycategory><address>Vodičkova 41</address><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.082053678544895</geolat><geolong>14.425467252731323</geolong></venue><venue><id>1323678</id><name>Pekařství Princess</name><primarycategory><id>79043</id><fullpathname>Food:Bakery</fullpathname><nodename>Bakery</nodename><iconurl>http://foursquare.com/img/categories/food/bakery.png</iconurl></primarycategory><address>Karlovo náměstí</address><crossstreet>Vestibul metra</crossstreet><city>Praha</city><state>Česká republika</state><zip>12800</zip><geolat>50.07595354755942</geolat><geolong>14.418890476226807</geolong></venue><venue><id>2216098</id><name>Piazzetta Národního divadla</name><primarycategory><id>79196</id><fullpathname>Parks &amp; Outdoors:Plaza / Square</fullpathname><nodename>Plaza / Square</nodename><iconurl>http://foursquare.com/img/categories/parks_outdoors/default.png</iconurl></primarycategory><address>Národní</address><crossstreet>Ostrovní</crossstreet><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.08090393895088</geolat><geolong>14.414223432540894</geolong></venue><venue><id>907214</id><name>Purkyňův ústav</name><primarycategory><id>79021</id><fullpathname>College &amp; Education:Medical School</fullpathname><nodename>Medical School</nodename><iconurl>http://foursquare.com/img/categories/education/medicalschool.png</iconurl></primarycategory><address>Albertov 4</address><city>Prague</city><state>Czech republic</state><geolat>50.068403044374904</geolat><geolong>14.42306399345398</geolong></venue><venue><id>2468832</id><name>Rossmann</name><primarycategory><id>79222</id><fullpathname>Shops:Drug Store / Pharmacy</fullpathname><nodename>Drug Store / Pharmacy</nodename><iconurl>http://foursquare.com/img/categories/shops/drugstore.png</iconurl></primarycategory><address>Vodičkova 710/31</address><crossstreet>Palackého</crossstreet><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.0813566</geolat><geolong>14.4242458</geolong></venue><venue><id>1660663</id><name>Strahovský klášter</name><primarycategory><id>79141</id><fullpathname>Home / Work / Other:Religious</fullpathname><nodename>Religious</nodename><iconurl>http://foursquare.com/img/categories/building/default.png</iconurl></primarycategory><address>Strahovské nádvoří</address><crossstreet>Pohořelec</crossstreet><city>Praha</city><state>Česká republika</state><zip>11800</zip><geolat>50.08683134289367</geolat><geolong>14.38934326171875</geolong></venue><venue><id>192336</id><name>Tesco</name><primarycategory><id>79221</id><fullpathname>Shops:Department Store</fullpathname><nodename>Department Store</nodename><iconurl>http://foursquare.com/img/categories/shops/default.png</iconurl></primarycategory><address>Skandinávská 144/25</address><city>Prague</city><state>Czech Republic</state><zip>155 00</zip><geolat>50.0495422</geolat><geolong>14.2954587</geolong></venue><venue><id>192468</id><name>Tesco</name><primarycategory><id>79221</id><fullpathname>Shops:Department Store</fullpathname><nodename>Department Store</nodename><iconurl>http://foursquare.com/img/categories/shops/default.png</iconurl></primarycategory><address>Národní třída 26</address><crossstreet>Spálená</crossstreet><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.08208121687963</geolat><geolong>14.419759511947632</geolong></venue><venue><id>2719697</id><name>Točená zmrzlina Minor</name><primarycategory><id>79067</id><fullpathname>Food:Ice Cream</fullpathname><nodename>Ice Cream</nodename><iconurl>http://foursquare.com/img/categories/food/icecream.png</iconurl></primarycategory><address>Vodičkova 6</address><crossstreet>Navrátilova</crossstreet><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.0785069</geolat><geolong>14.4218475</geolong></venue><venue><id>1000396</id><name>Unica Plasma</name><primarycategory><id>79134</id><fullpathname>Home / Work / Other:Medical</fullpathname><nodename>Medical</nodename><iconurl>http://foursquare.com/img/categories/building/medical.png</iconurl></primarycategory><address>Milady Horákové 109/116</address><crossstreet>K Brusce</crossstreet><city>Praha</city><state>Česká republika</state><zip>16000</zip><geolat>50.0969179</geolat><geolong>14.4046923</geolong></venue><venue><id>1665043</id><name>Velká strahovská zahrada</name><primarycategory><id>79194</id><fullpathname>Parks &amp; Outdoors:Park</fullpathname><nodename>Park</nodename><iconurl>http://foursquare.com/img/categories/parks_outdoors/default.png</iconurl></primarycategory><address>Vlašská</address><crossstreet>Úvoz</crossstreet><city>Praha</city><state>Česká republika</state><zip>11800</zip><geolat>50.08498642232332</geolat><geolong>14.392004013061523</geolong></venue><venue><id>1939842</id><name>Vrchlického sady</name><primarycategory><id>79194</id><fullpathname>Parks &amp; Outdoors:Park</fullpathname><nodename>Park</nodename><iconurl>http://foursquare.com/img/categories/parks_outdoors/default.png</iconurl></primarycategory><address>Vrchlického sady</address><crossstreet>Opletalova</crossstreet><city>Praha</city><state>Česká republika</state><zip>11000</zip><geolat>50.0836452</geolat><geolong>14.4333992</geolong></venue><venue><id>891769</id><name>Výtoň</name><primarycategory><id>79198</id><fullpathname>Parks &amp; Outdoors:Scenic Lookout</fullpathname><nodename>Scenic Lookout</nodename><iconurl>http://foursquare.com/img/categories/parks_outdoors/default.png</iconurl></primarycategory><address>Rašínovo nábřeží</address><crossstreet>Svobodova</crossstreet><city>Prague</city><state>Czech republic</state><geolat>50.067442361596015</geolat><geolong>14.414770603179932</geolong></venue><venue><id>1002025</id><name>ČVUT FEL</name><primarycategory><id>79037</id><fullpathname>College &amp; Education:University</fullpathname><nodename>University</nodename><iconurl>http://foursquare.com/img/categories/education/default.png</iconurl></primarycategory><address>Karlovo náměstí 13</address><crossstreet>Resslova</crossstreet><city>Prague</city><state>Czech republic</state><zip>12800</zip><geolat>50.07671094236536</geolat><geolong>14.41805362701416</geolong></venue></mayor></user>");
            }
            else
            {
                xml = Downloader.ProcessRequest(URL_USER_DETAIL, Downloader.METHOD_GET, parameters, this.username, this.password);
            }

            return new User(xml.GetElementsByTagName("user")[0]);
        }

        /// <summary>
        /// Returns a list of friends.
        /// </summary>
        /// <returns>list of friends</returns>
        public List<User> getFriends()
        {
            return getFriends(null);
        }

        /// <summary>
        /// Returns a list of friends.
        /// </summary>
        /// <param name="uid">user id of the person for whom you want to pull a friend graph</param>
        /// <returns>list of friends</returns>
        public List<User> getFriends(string uid)
        {
            string parameters = null;

            if (!String.IsNullOrEmpty(uid))
            {
                parameters = "uid=" + uid;
            }

            XmlDocument xml = Downloader.ProcessRequest(URL_FRIENDS, Downloader.METHOD_GET, parameters, this.username, this.password);

            XmlNode friends = xml.GetElementsByTagName("friends")[0];

            List<User> list = new List<User>();

            for (int i = 0; i < friends.ChildNodes.Count; i++)
            {
                list.Add(new User(friends.ChildNodes[i]));
            }

            return list;
        }

        ////////////////////////////////////////////////////////////////////////
        /// VENUE METHODS //////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns a list of venues near the area specified or that match the search term.
        /// </summary>
        /// <param name="geolat">latitude (required)</param>
        /// <param name="geolong">longitude (required)</param>
        /// <param name="keyword">keyword search (optional)</param>
        /// <returns>list of venues near the area</returns>
        public List<Group> searchVenuesNearby(string geolat, string geolong)
        {
            return this.searchVenuesNearby(geolat, geolong, 0, null);
        }

        /// <summary>
        /// Returns a list of venues near the area specified or that match the search term.
        /// </summary>
        /// <param name="geolat">latitude (required)</param>
        /// <param name="geolong">longitude (required)</param>
        /// <param name="keyword">keyword search (optional)</param>
        /// <returns>list of venues near the area</returns>
        public List<Group> searchVenuesNearby(string geolat, string geolong, string keyword)
        {
            return this.searchVenuesNearby(geolat, geolong, 0, keyword);
        }

        /// <summary>
        /// Returns a list of venues near the area specified or that match the search term.
        /// </summary>
        /// <param name="geolat">latitude (required)</param>
        /// <param name="geolong">longitude (required)</param>
        /// <param name="limit">limit of results (optional, default 10, maximum 50)</param>
        /// <param name="keyword">keyword search (optional)</param>
        /// <returns>list of venues near the area</returns>
        public List<Group> searchVenuesNearby(string geolat, string geolong, int limit, string keyword)
        {
            if (String.IsNullOrEmpty(geolat) || String.IsNullOrEmpty(geolong))
            {
                throw new IOException("Latitude and Longitude must be setted.");
            }

            string parameters = "geolat=" + geolat + "&geolong=" + geolong;

            if (limit > 0)
            {
                parameters += "&l=" + limit;
            }

            if (!String.IsNullOrEmpty(keyword))
            {
                parameters += "&q=" + HttpUtility.UrlEncode(keyword);
            }
            
            XmlDocument xml;

            if (this.debug)
            {
                xml = Downloader.stringToXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?><venues><group type=\"My Favorites\"><venue><id>3399444</id><name>Mini Market</name><primarycategory><id>79235</id><fullpathname>Shops:Food &amp; Drink:Grocery / Supermarket</fullpathname><nodename>Grocery / Supermarket</nodename><iconurl>http://foursquare.com/img/categories/shops/food_grocery.png</iconurl></primarycategory><address>Komořanská 2000/50</address><crossstreet>Na Homoli</crossstreet><city>Praha</city><state>Česká republika</state><zip>14300</zip><geolat>49.9901291</geolat><geolong>14.4094153</geolong><stats><herenow>0</herenow></stats><distance>111</distance></venue><venue><id>3671605</id><name>Potraviny</name><address>Komořanská 2168</address><crossstreet>Okružní</crossstreet><city>Praha</city><state>Česká republika</state><zip>14300</zip><geolat>49.9909024</geolat><geolong>14.409704</geolong><stats><herenow>0</herenow></stats><distance>71</distance></venue></group><group type=\"Nearby\"><venue><id>3007453</id><name>Praha - Komořany</name><primarycategory><id>79132</id><fullpathname>Home / Work / Other:Home</fullpathname><nodename>Home</nodename><iconurl>http://foursquare.com/img/categories/building/home.png</iconurl></primarycategory><address>Komořanská</address><crossstreet>Revoluce</crossstreet><city>Praha</city><state>Česko</state><zip>14300</zip><geolat>49.9899735615043</geolat><geolong>14.409470558166504</geolong><stats><herenow>1</herenow></stats><distance>129</distance></venue><venue><id>3399620</id><name>Nádraží Komořany</name><primarycategory><id>96363</id><fullpathname>Travel:Train Station:Train</fullpathname><nodename>Train</nodename><iconurl>http://foursquare.com/img/categories/travel/trainstation.png</iconurl></primarycategory><address>U Skladu</address><crossstreet>U Soutoku</crossstreet><city>Praha</city><state>Česká republika</state><zip>14300</zip><geolat>49.99085302309282</geolat><geolong>14.404438734054565</geolong><stats><herenow>0</herenow></stats><distance>307</distance></venue><venue><id>2664926</id><name>In-Line Bistro</name><primarycategory><id>79066</id><fullpathname>Food:Hot Dogs</fullpathname><nodename>Hot Dogs</nodename><iconurl>http://foursquare.com/img/categories/food/hotdog.png</iconurl></primarycategory><address></address><city></city><state></state><geolat>49.994513</geolat><geolong>14.404589</geolong><stats><herenow>0</herenow></stats><distance>487</distance></venue><venue><id>1614452</id><name>Nádraží Modřany</name><primarycategory><id>96363</id><fullpathname>Travel:Train Station:Train</fullpathname><nodename>Train</nodename><iconurl>http://foursquare.com/img/categories/travel/trainstation.png</iconurl></primarycategory><address>U Kina</address><crossstreet>Vltavanů</crossstreet><city>Prague</city><state>Prague</state><zip>143 00</zip><geolat>50.0042292028687</geolat><geolong>14.403172731399536</geolong><stats><herenow>0</herenow></stats><distance>1522</distance></venue><venue><id>2554093</id><name>Pečivo Gama</name><primarycategory><id>79043</id><fullpathname>Food:Bakery</fullpathname><nodename>Bakery</nodename><iconurl>http://foursquare.com/img/categories/food/bakery.png</iconurl></primarycategory><address>Komořanská</address><crossstreet>Kyslíková</crossstreet><city>Praha</city><state>Česká republika</state><zip>14300</zip><geolat>49.991197905600245</geolat><geolong>14.41079556941986</geolong><stats><herenow>0</herenow></stats><distance>149</distance></venue><venue><id>2546153</id><name>Přívoz P6</name><primarycategory><id>79270</id><fullpathname>Travel:Boat / Ferry</fullpathname><nodename>Boat / Ferry</nodename><iconurl>http://foursquare.com/img/categories/travel/boat.png</iconurl></primarycategory><address>U Kina</address><crossstreet>K Sádkám</crossstreet><city>Praha</city><state>Česká republika</state><zip>14300</zip><geolat>50.002777624269996</geolat><geolong>14.402700662612915</geolong><stats><herenow>0</herenow></stats><distance>1376</distance></venue><venue><id>1709082</id><name>Studio 8</name><primarycategory><id>79140</id><fullpathname>Home / Work / Other:Other - Buildings</fullpathname><nodename>Other - Buildings</nodename><iconurl>http://foursquare.com/img/categories/building/default.png</iconurl></primarycategory><address>Komořany</address><city>Praha</city><state>Hlavní město Praha</state><geolat>49.9896136</geolat><geolong>14.4092807</geolong><stats><herenow>0</herenow></stats><distance>162</distance></venue><venue><id>1445186</id><name>Česká pošta</name><primarycategory><id>96360</id><fullpathname>Shops:Post Office</fullpathname><nodename>Post Office</nodename><iconurl>http://foursquare.com/img/categories/shops/postoffice.png</iconurl></primarycategory><address>Sofijské náměstí 3406/1</address><crossstreet>Československého exilu</crossstreet><city>Praha</city><state>Česká republika</state><zip>14300</zip><geolat>50.00531872000257</geolat><geolong>14.417270421981812</geolong><stats><herenow>0</herenow></stats><distance>1704</distance></venue><venue><id>3371267</id><name>Cinemax</name><primarycategory><id>79115</id><fullpathname>Home / Work / Other:Corporate / Office</fullpathname><nodename>Corporate / Office</nodename><iconurl>http://foursquare.com/img/categories/building/default.png</iconurl></primarycategory><address>Elisky Premyslovny 433</address><city></city><state>Hlavní město Praha</state><geolat>49.982874</geolat><geolong>14.395062</geolong><stats><herenow>0</herenow></stats><distance>1334</distance></venue><venue><id>2720069</id><name>Cafe Deco</name><primarycategory><id>79049</id><fullpathname>Food:Café</fullpathname><nodename>Café</nodename><iconurl>http://foursquare.com/img/categories/food/cafe.png</iconurl></primarycategory><address></address><city></city><state></state><geolat>49.99772</geolat><geolong>14.396919</geolong><stats><herenow>0</herenow></stats><distance>1126</distance></venue></group></venues>");
            }
            else
            {
                xml = Downloader.ProcessRequest(URL_SEARCH_NEARBY, Downloader.METHOD_GET, parameters, this.username, this.password);
            }

            XmlNode venues = xml.GetElementsByTagName("venues")[0];

            List<Group> list = new List<Group>();

            for (int i = 0; i < venues.ChildNodes.Count; i++)
            {
                list.Add(new Group(venues.ChildNodes[i]));
            }

            return list;
        }

        /// <summary>
        /// Returns venue data, including mayorship, tips/to-dos and tags.
        /// </summary>
        /// <param name="vid">the ID for the venue for which you want information</param>
        /// <returns>venue details</returns>
        public Venue getVenueDetails(string vid)
        {
            if (String.IsNullOrEmpty(vid))
            {
                throw new IOException("Venue ID must be setted.");
            }

            string parameters = "vid=" + vid;

            XmlDocument xml = Downloader.ProcessRequest(URL_VENUE_DETAILS, Downloader.METHOD_GET, parameters, this.username, this.password);

            return new Venue(xml.GetElementsByTagName("venue")[0]);
        }

        /// <summary>
        /// Allows you to add a new venue.
        /// </summary>
        /// <param name="name">the name of the venue</param>
        /// <param name="address">(optional) the address of the venue (e.g., "202 1st Avenue")</param>
        /// <param name="crossstreet">(optional) the cross streets (e.g., "btw Grand & Broome")</param>
        /// <param name="city">(optional) the city name where this venue is</param>
        /// <param name="state">(optional) the state where the city is</param>
        /// <param name="zip">(optional) the ZIP code for the venue</param>
        /// <param name="phone">(optional) the phone number for the venue</param>
        /// <param name="geolat">(optional, but recommended)</param>
        /// <param name="geolong">(optional, but recommended)</param>
        /// <param name="primarycategoryid">(optional) the ID of the category to which you want to assign this venue</param>
        /// <returns>added venue</returns>
        public Venue addVenue(string name, string address, string crossstreet,
            string city, string state, string zip, string phone, string geolat,
            string geolong, string primarycategoryid)
        {
            throw new Exception("Not implemented yet!");
        }

        /// <summary>
        /// Allows you to flag/propose a change to a venue.
        /// </summary>
        /// <param name="vid">(required) the venue for which you want to propose an edit</param>
        /// <param name="name">(required) the name of the venue</param>
        /// <param name="address">(required) the address of the venue (e.g., "202 1st Avenue")</param>
        /// <param name="crossstreet">the cross streets (e.g., "btw Grand & Broome")</param>
        /// <param name="city">(required) the city name where this venue is</param>
        /// <param name="state">(required) the state where the city is</param>
        /// <param name="zip">(optional) the ZIP code for the venue</param>
        /// <param name="phone">(optional) the phone number for the venue</param>
        /// <param name="geolat">(required)</param>
        /// <param name="geolong">(required)</param>
        /// <returns></returns>
        public bool proposeVenueEdit(string vid, string name, string address,
            string crossstreet, string city, string state, string zip,
            string phone, string geolat, string geolong)
        {
            throw new Exception("Not implemented yet!");
        }

        ////////////////////////////////////////////////////////////////////////
        /// TIP METHODS ////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns a list of tips near the area specified.
        /// </summary>
        /// <param name="geolat">latitude (required)</param>
        /// <param name="geolong">longitude (required)</param>
        /// <param name="limit">limit of results (optional, default 30)</param>
        /// <returns>list of tips</returns>
        public List<Tip> seachTipsNearby(string geolat, string geolong)
        {
            return this.seachTipsNearby(geolat, geolong, 0);
        }

        /// <summary>
        /// Returns a list of tips near the area specified.
        /// </summary>
        /// <param name="geolat">latitude (required)</param>
        /// <param name="geolong">longitude (required)</param>
        /// <param name="limit">limit of results (optional, default 30)</param>
        /// <returns>list of tips</returns>
        public List<Tip> seachTipsNearby(string geolat, string geolong, int limit)
        {
            if (String.IsNullOrEmpty(geolat) || String.IsNullOrEmpty(geolong))
            {
                throw new IOException("Latitude and Longitude must be setted.");
            }

            string parameters = "geolat=" + geolat + "&geolong=" + geolong;

            if (limit > 0)
            {
                parameters += "&l=" + limit;
            }

            XmlDocument xml = Downloader.ProcessRequest(URL_TIPS_NEARBY, Downloader.METHOD_GET, parameters, this.username, this.password);
            
            XmlNode group = xml.GetElementsByTagName("group")[0];

            List<Tip> list = new List<Tip>();

            for (int i = 0; i < group.ChildNodes.Count; i++)
            {
                list.Add(new Tip(group.ChildNodes[i]));
            }

            return list;
        }

        /// <summary>
        /// Allows you to add a new tip or to-do at a venue.
        /// </summary>
        /// <param name="vid">the venue where you want to add this tip (required)</param>
        /// <param name="text">the text of the tip or to-do item (required)</param>
        /// <returns>added tip</returns>
        public Tip addTip(string vid, string text)
        {
            return this.addTip(vid, text, "tip", null, null);
        }

        /// <summary>
        /// Allows you to add a new tip or to-do at a venue.
        /// </summary>
        /// <param name="vid">the venue where you want to add this tip (required)</param>
        /// <param name="text">the text of the tip or to-do item (required)</param>
        /// <param name="type">specify one of 'tip' or 'todo' (optional, default: tip)</param>
        /// <returns>added tip</returns>
        public Tip addTip(string vid, string text, string type)
        {
            return this.addTip(vid, text, type, null, null);
        }

        /// <summary>
        /// Allows you to add a new tip or to-do at a venue.
        /// </summary>
        /// <param name="vid">the venue where you want to add this tip (required)</param>
        /// <param name="text">the text of the tip or to-do item (required)</param>
        /// <param name="geolat">(optional, but recommended)</param>
        /// <param name="geolong">(optional, but recommended)</param>
        /// <returns>added tip</returns>
        public Tip addTip(string vid, string text, string geolat, string geolong)
        {
            return this.addTip(vid, text, "tip", geolat, geolong);
        }

        /// <summary>
        /// Allows you to add a new tip or to-do at a venue.
        /// </summary>
        /// <param name="vid">the venue where you want to add this tip (required)</param>
        /// <param name="text">the text of the tip or to-do item (required)</param>
        /// <param name="type">specify one of 'tip' or 'todo' (optional, default: tip)</param>
        /// <param name="geolat">(optional, but recommended)</param>
        /// <param name="geolong">(optional, but recommended)</param>
        /// <returns>added tip</returns>
        public Tip addTip(string vid, string text, string type, string geolat, string geolong)
        {
            if (String.IsNullOrEmpty(vid) || String.IsNullOrEmpty(text))
            {
                throw new IOException("Venue ID and Text must be setted.");
            }

            string parameters = "vid=" + vid + "&text=" + HttpUtility.UrlEncode(text);

            if (type == "todo")
            {
                parameters += "type=" + type;
            }

            if (geolat != null && geolat != "" && geolong != null && geolong != "")
            {
                 parameters += "&geolat=" + geolat + "&geolong=" + geolong;
            }

            XmlDocument xml = Downloader.ProcessRequest(URL_ADD_TIP, Downloader.METHOD_POST, parameters, this.username, this.password);

            XmlNode tip = xml.GetElementsByTagName("tip")[0];

            return new Tip(tip);
        }

        /// <summary>
        /// Allows you to mark a tip as a to-do item.
        /// </summary>
        /// <param name="tid">the tip that you want to mark to-do (required)</param>
        /// <returns>marked tip</returns>
        public Tip markTipAsTodo(string tid)
        {
            if (String.IsNullOrEmpty(tid))
            {
                throw new IOException("Tip ID must be setted.");
            }

            string parameters = "tid=" + tid;

            XmlDocument xml = Downloader.ProcessRequest(URL_MARK_TODO, Downloader.METHOD_POST, parameters, this.username, this.password);

            XmlNode tip = xml.GetElementsByTagName("tip")[0];

            return new Tip(tip);
        }

        /// <summary>
        /// Allows you to mark a tip as done.
        /// </summary>
        /// <param name="tid">the tip that you want to mark done (required)</param>
        /// <returns>marked tip</returns>
        public Tip markTipAsDone(string tid)
        {
            if (String.IsNullOrEmpty(tid))
            {
                throw new IOException("Tip ID must be setted.");
            }

            string parameters = "tid=" + tid;

            XmlDocument xml = Downloader.ProcessRequest(URL_MARK_DONE, Downloader.METHOD_POST, parameters, this.username, this.password);

            XmlNode tip = xml.GetElementsByTagName("tip")[0];

            return new Tip(tip);
        }

        /// <summary>
        /// Allows you to unmark a tip (it will revert the previous action, if there was any on the tip).
        /// </summary>
        /// <param name="tid">the tip that you want to unmark (required)</param>
        /// <returns>unmarked tip</returns>
        public Tip unmarkTip(string tid)
        {
            if (String.IsNullOrEmpty(tid))
            {
                throw new IOException("Tip ID must be setted.");
            }

            string parameters = "tid=" + tid;

            XmlDocument xml = Downloader.ProcessRequest(URL_UNMARK, Downloader.METHOD_POST, parameters, this.username, this.password);

            XmlNode tip = xml.GetElementsByTagName("tip")[0];

            return new Tip(tip);
        }

        ////////////////////////////////////////////////////////////////////////
        /// FRIEND METHODS /////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Shows you a list of users with whom you have a pending friend request (ie, they've requested to add you as a friend, but you have not approved).
        /// </summary>
        /// <returns>list of users with whom you have a pending friend request</returns>
        public List<User> getPengingFriendRequests()
        {
            XmlDocument xml = Downloader.ProcessRequest(URL_PENDING_REQUESTS, Downloader.METHOD_GET, null, this.username, this.password);

            XmlNode requests = xml.GetElementsByTagName("requests")[0];

            List<User> list = new List<User>();

            for (int i = 0; i < requests.ChildNodes.Count; i++)
            {
                list.Add(new User(requests.ChildNodes[i]));
            }

            return list;
        }

        /// <summary>
        /// Approves a pending friend request from another user.
        /// </summary>
        /// <param name="uid">the user ID of the user who you want to approve</param>
        /// <returns></returns>
        public User approveFriendRequest(string uid)
        {
            if (String.IsNullOrEmpty(uid))
            {
                throw new IOException("User ID must be setted.");
            }

            string parameters = "uid=" + uid;

            XmlDocument xml = Downloader.ProcessRequest(URL_APPROVE_REQUEST, Downloader.METHOD_POST, parameters, this.username, this.password);

            XmlNode user = xml.GetElementsByTagName("user")[0];

            return new User(user);
        }

        /// <summary>
        /// Denies a pending friend request from another user.
        /// </summary>
        /// <param name="uid">the user ID of the user who you want to deny</param>
        /// <returns></returns>
        public User denyFriendRequest(string uid)
        {
            if (String.IsNullOrEmpty(uid))
            {
                throw new IOException("User ID must be setted.");
            }

            string parameters = "uid=" + uid;

            XmlDocument xml = Downloader.ProcessRequest(URL_DENY_REQUEST, Downloader.METHOD_POST, parameters, this.username, this.password);

            XmlNode user = xml.GetElementsByTagName("user")[0];

            return new User(user);
        }

        /// <summary>
        /// Sends a friend request to another user.
        /// </summary>
        /// <param name="uid">the user ID of the user to whom you want to send a friend request</param>
        /// <returns></returns>
        public User sendFriendRequest(string uid)
        {
            if (String.IsNullOrEmpty(uid))
            {
                throw new IOException("User ID must be setted.");
            }

            string parameters = "uid=" + uid;

            XmlDocument xml = Downloader.ProcessRequest(URL_SEND_REQUEST, Downloader.METHOD_POST, parameters, this.username, this.password);

            XmlNode user = xml.GetElementsByTagName("user")[0];

            return new User(user);
        }

        /// <summary>
        /// Searches friends by using a name.
        /// </summary>
        /// <param name="q">the string you want to use to search firstnames and lastnames</param>
        /// <returns>list of people with whom you are not already friends</returns>
        public List<User> findFriendsByName(string q)
        {
            if (String.IsNullOrEmpty(q))
            {
                throw new IOException("Searched string must be setted.");
            }

            string parameters = "q=" + HttpUtility.UrlEncode(q);

            XmlDocument xml = Downloader.ProcessRequest(URL_BY_NAME, Downloader.METHOD_GET, parameters, this.username, this.password);

            XmlNode users = xml.GetElementsByTagName("users")[0];

            List<User> list = new List<User>();

            for (int i = 0; i < users.ChildNodes.Count; i++)
            {
                list.Add(new User(users.ChildNodes[i]));
            }

            return list;
        }

        /// <summary>
        /// Searches friends by using a phone number.
        /// </summary>
        /// <param name="q">the string you want to use to search for phone numbers</param>
        /// <returns>list of people with whom you are not already friends</returns>
        public List<User> findFriendsByPhone(string q)
        {
            if (String.IsNullOrEmpty(q))
            {
                throw new IOException("Searched string must be setted.");
            }

            string parameters = "q=" + HttpUtility.UrlEncode(q);

            XmlDocument xml = Downloader.ProcessRequest(URL_BY_PHONE, Downloader.METHOD_GET, parameters, this.username, this.password);

            XmlNode users = xml.GetElementsByTagName("users")[0];

            List<User> list = new List<User>();

            for (int i = 0; i < users.ChildNodes.Count; i++)
            {
                list.Add(new User(users.ChildNodes[i]));
            }

            return list;
        }

        /// <summary>
        /// Searches friends by using a Twitter name.
        /// </summary>
        /// <param name="q">(optional) the Twitter name you want to use to search</param>
        /// <returns>list of people with whom you are not already friends</returns>
        public List<User> findFriendsByTwitter(string q)
        {
            if (String.IsNullOrEmpty(q))
            {
                throw new IOException("Searched string must be setted.");
            }

            string parameters = "q=" + HttpUtility.UrlEncode(q);

            XmlDocument xml = Downloader.ProcessRequest(URL_BY_TWITTER, Downloader.METHOD_GET, parameters, this.username, this.password);

            XmlNode users = xml.GetElementsByTagName("users")[0];

            List<User> list = new List<User>();

            for (int i = 0; i < users.ChildNodes.Count; i++)
            {
                list.Add(new User(users.ChildNodes[i]));
            }

            return list;
        }

        ////////////////////////////////////////////////////////////////////////
        /// SETTINGS METHODS ///////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Allows you to change notification options for yourself (self) globally as well as for each individual friend (identified by their uid).
        /// </summary>
        /// <param name="self">the ping status for yourself (globally). possible values are on, off and goodnight.</param>
        /// <param name="uids">set the ping status for a friend. possible values are on and off.</param>
        /// <returns></returns>
        public bool setPings(string self, string uids){
            throw new Exception("Not implemented yet!");
        }

        ////////////////////////////////////////////////////////////////////////
        /// OTHER METHODS //////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool test()
        {
            XmlDocument xml = Downloader.ProcessRequest(URL_TEST, Downloader.METHOD_GET, null, null, null);

            XmlNodeList list = xml.GetElementsByTagName("response");

            return list.Count > 0 && list[0].InnerText == "ok";
        }
    }
}
